
_realname=krita
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.1.5
pkgrel=1
pkgdesc="A professional FREE and open source painting program"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://krita.org/"
license=("spdx:GPL-3.0-only")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-eigen3"
  "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
  "${MINGW_PACKAGE_PREFIX}-kdoctools-qt5"
  "${MINGW_PACKAGE_PREFIX}-libheif"
  "${MINGW_PACKAGE_PREFIX}-libjxl"
  "${MINGW_PACKAGE_PREFIX}-libmypaint"
  "${MINGW_PACKAGE_PREFIX}-poppler-qt5"
  "${MINGW_PACKAGE_PREFIX}-python-pyqt5"
  "${MINGW_PACKAGE_PREFIX}-qt5-tools"
  "${MINGW_PACKAGE_PREFIX}-sip"
  "${MINGW_PACKAGE_PREFIX}-xsimd"
)
depends=(
  "${MINGW_PACKAGE_PREFIX}-angleproject"
  "${MINGW_PACKAGE_PREFIX}-exiv2"
  "${MINGW_PACKAGE_PREFIX}-fftw"
  "${MINGW_PACKAGE_PREFIX}-gsl"
  "${MINGW_PACKAGE_PREFIX}-icoutils"
  "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
  "${MINGW_PACKAGE_PREFIX}-kcompletion-qt5"
  "${MINGW_PACKAGE_PREFIX}-kcoreaddons-qt5"
  "${MINGW_PACKAGE_PREFIX}-kguiaddons-qt5"
  "${MINGW_PACKAGE_PREFIX}-kwindowsystem-qt5"
  "${MINGW_PACKAGE_PREFIX}-ki18n-qt5"
  "${MINGW_PACKAGE_PREFIX}-kitemmodels-qt5"
  "${MINGW_PACKAGE_PREFIX}-kitemviews-qt5"
  "${MINGW_PACKAGE_PREFIX}-kseexpr"
  "${MINGW_PACKAGE_PREFIX}-libraw"
  "${MINGW_PACKAGE_PREFIX}-libwebp"
  "${MINGW_PACKAGE_PREFIX}-opencolorio"
  "${MINGW_PACKAGE_PREFIX}-openexr"
  "${MINGW_PACKAGE_PREFIX}-openjpeg2"
  "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
  "${MINGW_PACKAGE_PREFIX}-qt5-svg"
  "${MINGW_PACKAGE_PREFIX}-quazip-qt5"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-ffmpeg: Support for saving animations"
  "${MINGW_PACKAGE_PREFIX}-kimageformats-qt5: Support for PSD files"
  "${MINGW_PACKAGE_PREFIX}-libmypaint: Support for MyPaint brushes"
)
source=("https://download.kde.org/stable/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.xz"
        001-mingw-interface-conflict.patch
        002-exiv2-missing-wpath.patch
        003-xsimd-10.patch::https://github.com/KDE/krita/commit/8b787f8acd04370625d5c4c931deaf123cecffab.patch
        004-qt5-qguiapplication.patch
        005-no-installer.patch)
sha256sums=('45eac209a3c4ac285ca223e1978d35694cdca31b0075e596ad252d6619f04249'
            'adc55086f79728127dc03a6b09560c0166a64aefb0e227177bd9d964c9491d58'
            'b6488900406bca3fb6d24aa323abb565dd5192abab60adb8b12e2cdae20713a5'
            '0ef2bb98ea7db284c3e38d804385c5e9e6a5ae32011e77f669fcd3bc4568065f'
            'd28d14e7e162c369ef0088ecb81196b7ce97f85dd302b4ef0de71e0fb2f474e2'
            'd80a2728692a1456b133a17e33a0083adab8c96270b4d6e94da07ed8141c4503')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/001-mingw-interface-conflict.patch"
  patch -Np1 -i "${srcdir}/002-exiv2-missing-wpath.patch"
  patch -Np1 -i "${srcdir}/003-xsimd-10.patch"

  # Workaround for https://bugreports.qt.io/browse/QTBUG-111527
  patch -Np1 -i "${srcdir}/004-qt5-qguiapplication.patch"

  patch -Np1 -i "${srcdir}/005-no-installer.patch"
}

build() {
  [[ -d "build-${MSYSTEM}" ]] && rm -rf "build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -GNinja \
    -DCMAKE_BUILD_TYPE="Release" \
    -DBUILD_TESTING="OFF" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -vDm 644 ${srcdir}/${_realname}-${pkgver}/COPYING -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/"
  install -vDm 644 ${srcdir}/${_realname}-${pkgver}/{AUTHORS,README.md} -t "${pkgdir}${MINGW_PREFIX}/share/doc/$_realname/"
}